package while_lang.tests;

import java.util.Random;
import junit.framework.TestCase;
import while_lang.ast.*;
import while_lang.parser.ParserCup;

public class ParserTests extends TestCase {

	public void testParsingUnparsedCode() throws Exception {
		Random random = new Random(123456L);
		for (int i = 0; i < 300; i++) {
			Sequence ast = Sequence.generate(random, i / 30, i / 25);
			String unparsed = ast.unparse();
			Sequence parsed;
			try {
				parsed = ParserCup.parseString(unparsed);
			} catch (Exception err) {
				System.err.println("Error parsing:\n"+ unparsed);
				throw err;
			}
			assertEquals(unparsed, parsed.unparse());
		}		
	}
	
}
